<?php
require_once HOME . DS . 'application'. DS.  'controllers' . DS . 'productcontroller.php';
$controller = "home";
$action = "index";
$query = null;

//echo $url;


// Parse URL for get Controller and Action
if (isset($url) and ($url != '/') and (!preg_match("/\?code=/i", $url))) {

    $params = array();
    $params = explode("/", $url);

    $controller = $params[1];


    if (isset($params[2]) && !empty($params[2])) {
        $action = $params[2];
    }

    if (isset($params[3]) && !empty($params[3])) {
        $query = $params[3];
    }
}


// Assign new Controller from URL Request
$modelName = $controller;
$controller .= 'Controller';

$load = new $controller($modelName, $action);

if (method_exists($load, $action)) {
    $load->{$action}($query);
} else {
    die('Invalid method. Please check the URL.');
}
